package com.zlcx.tz.live.processor.impl;

import com.zlcx.tz.live.domain.TimeLearnRoomUsersDO;
import com.zlcx.tz.live.exception.UnRoomUserException;
import com.zlcx.tz.live.processor.JoinRoomPostProcessor;
import com.zlcx.tz.live.service.impl.TimeLearnRoomServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: anjl
 * @description: 加入房间后，在会话中添加用户，通过执行心跳的方式实现，
 * 立刻执行一次心跳，将房间信息更新到会话中
 * 会话的通过心跳长期保持，3次没有心跳，会话会自动被移除
 * @data: 2020-09-29
 **/
@Slf4j
@Component
public class JoinRoomDialogPostProcessor implements JoinRoomPostProcessor<TimeLearnRoomUsersDO> {

    @Override
    public void processor(TimeLearnRoomUsersDO roomUsers) {
        try {
            timeLearnRoomService.heart(roomUsers.getRoomId(), roomUsers.getUserId());
        } catch (UnRoomUserException e) {
            e.printStackTrace();
        }
        log.info("计时房间操作-添加redis房间会话用户 roomUsers = {}", roomUsers);
    }

    @Autowired
    private TimeLearnRoomServiceImpl timeLearnRoomService;

}
